<template>
	<view style="padding-bottom: 120rpx;">
		<view class="box">
			<view class="flex align-center ">
				<view class="titls" v-if="order.indentState==0">待接单</view>
				<view class="titls" v-if="order.indentState==1">已接单</view>
				<view class="titls" v-if="order.indentState==2">进行中</view>
				<view class="titls" v-if="order.indentState==3">待支付</view>
				<view class="titls" v-if="order.indentState==4">已完成</view>
				<view class="titls" v-if="order.indentState==5">已取消</view>
				<view class="bb" v-if="order.indentType==1"> 即时代驾</view>
				<view class="bb" v-if="order.indentType==2">朋友代叫</view>
				<view class="bb" v-if="order.indentType==3">预约代驾</view>
				<view class="bb" v-if="order.indentType==4">包时代驾</view>
			</view>
			<view class="margin-top-xs" style="color: #999999;" v-if="order.indentState==0">等待附近司机接单...</view>
			<view class="margin-top-xs" style="color: #999999;" v-if="order.indentState==1">司机正在努力赶来</view>
			<view class="margin-top-xs" style="color: #999999;" v-if="order.indentState==5">订单已取消，再来一单</view>
			<view class="margin-top-xs" style="color: #999999;" v-if="order.indentState==2">订单进行中</view>
			<view class="margin-top-xs" style="color: #999999;" v-if="order.indentState==3">已到达终点,待用户支付</view>
			<view class="margin-top-xs" style="color: #999999;" v-if="order.indentState==4">订单已完成</view>
			<!-- <view class="flex align-center ">
				<view class="titls">进行中</view>
				<view class="bb">即时代驾</view>
			</view> -->
			<!-- <view class="margin-top-xs" style="color: #999999;">司机正在努力赶来</view> -->
			<!-- <view class="titls">待抵达...</view> -->
			<!-- <view class="margin-top-xs" style="color: #999999;">抢单成功请及时取货送达</view> -->
		</view>


		<view class="boxa">
			<view class="flex align-center justify-between padding-lr">
				<view class="flex align-center">
					<image src="../static/data.png" style="width: 34rpx;height: 38rpx;"></image>
					<view class="margin-left-sm" v-if="order.indentType==1"> 即时代驾</view>
					<view class="margin-left-sm" v-if="order.indentType==2">朋友代叫</view>
					<view class="margin-left-sm" v-if="order.indentType==3">预约代驾</view>
					<view class="margin-left-sm" v-if="order.indentType==4">包时代驾</view>
				</view>
				<view class="text-26" v-if="order.distance">全程公里数
					<text style="color: #3699FF;">{{Number(order.distance).toFixed(2)}}km</text>
				</view>
			</view>
			<view class="margin-tb-sm" style="width: 100%;height:1rpx;background: #F2F2F2;"></view>
			<view class="addbox bgs margin-lr margin-bottom"
				@click="openMap(order.shipAddressLatitude,order.shipAddressLongitude,order.shipAddress)">
				<view class="add_cont">
					<view class="green"></view>
					<view class="add_tit">{{order.shipAddress}}</view>
				</view>
				<view>
					<image src="../../static/image/ladd.png" style="width: 26rpx;height:31rpx;"></image>
				</view>
			</view>
			<view class="addbox bg margin-lr"
				@click="order.deliveryAddress?openMap(order.deliveryAddressLatitude,order.deliveryAddressLongitude,order.deliveryAddress):''">
				<view class="add_cont">
					<view class="orgin"></view>
					<view class="add_tit">{{order.deliveryAddress?order.deliveryAddress:'用户未选择目的地'}}</view>
				</view>
				<view>
					<image src="../../static/image/hadd.png" style="width: 26rpx;height: 31rpx;"></image>
				</view>
			</view>
			<view class="margin-tb-sm" style="width: 100%;height:1rpx;background: #F2F2F2;"></view>
			<view class="flex align-center justify-between padding-lr ">
				<view class="flex align-center" v-if="order.riderDistance">
					<image src="../../static/image/add.png" style="width: 26rpx;height: 31rpx;"></image>
					<view class="margin-left-xs">距您
						<text style="color: #3699FF;">
							{{(Number(order.riderDistance) ).toFixed(2)}}km
						</text>
					</view>

				</view>
				<view class="flex align-center " v-if="order.indentState==3">
					<text>用户待支付</text>
					<view style="color: #FF2020;font-size: 32rpx;">
						<text>¥</text>
						<text class="text-bold" style="font-size: 38rpx;">{{order.estimateMoney}}</text>
					</view>
				</view>
				<view class="flex align-center ">
					<view v-if="order.areaId">一口价</view>
					<text v-if="order.indentState!=4">预估</text>
					<text v-else>实收</text>
					<view style="color: #FF2020;font-size: 32rpx;">
						<text>¥</text>
						<text class="text-bold" style="font-size: 38rpx;">{{order.riderMoney}}</text>
					</view>
				</view>
				<view class="flex align-center text-sm" v-if="order.indentState==1 && order.startWaitTime">
					等待时长：<smh-timer ref="timer" @timing="timing" :auto="order.isTime"
						:numberminutes="order.numberminutes"></smh-timer>
				</view>

			</view>
		</view>

		<view class="box flex align-center" v-if="order.indentState!=0 && order.userId">
			<image :src="order.avatar?order.avatar:'../../static/image/logo.png'"
				style="width: 90rpx;height: 90rpx;border-radius: 50%;"></image>
			<view class="margin-left-sm flex align-center justify-between" style="width: 80%;">
				<view>
					<view class="titls">{{order.shipUserName}}</view>
					<view class="margin-top-xs" style="color: #999999;font-size: 26rpx;">{{order.shipPhone}}
					</view>
				</view>
				<view @click="bindPhone(order.shipUserPhone)" v-if="order.isData">
					<image src="../static/phone.png" style="width: 42rpx;height: 52rpx;"></image>
				</view>
			</view>
		</view>
		<view class="box" v-if="order.indentState==4&&order.evaluateMessage">
			<view class="titls margin-bottom-sm">用户评价</view>
			<!-- <view class="" v-if="order.evaluate==0">满意</view>
			<view class="" v-if="order.evaluate==1">不满意</view> -->
			<view class="margin-top-xs">{{order.evaluateMessage}}</view>
		</view>
		<view class="box " style="color: #999999;">
			<view class="titls">订单信息</view>
			<view v-if="order.indentType==2">
				<view class="flex align-center justify-between margin-tb">
					<view>付款对象</view>
					<view v-if="order.payUser==0">下单人</view>
					<view v-if="order.payUser==1">乘车人</view>
				</view>
				<view class="flex align-center justify-between margin-tb">
					<view>乘车人</view>
					<view>{{order.customName}}</view>
				</view>
				<view class="flex align-center justify-between margin-tb">
					<view>乘车人电话</view>
					<view @click="bindPhone(order.customPhone)">{{order.customPhones}}
						<image src="../static/ic_phone.png" style="width: 25rpx;height: 28rpx;"></image>
					</view>
				</view>
			</view>
			<view v-if="order.indentType==3">
				<view class="flex align-center justify-between margin-tb">
					<view>预约时间</view>
					<view>{{order.hopeTime}}</view>
				</view>
			</view>
			<view class="flex align-center justify-between margin-tb" v-if="order.timeNum">
				<view>包时时长</view>
				<view>{{order.timeNum}}分钟</view>
			</view>
			<view v-if="order.indentState==3||order.indentState==4">
				<!-- <view v-if="order.timeId">
					<view class="flex align-center justify-between margin-tb">
						<view>包时(小时)</view>
						<view>{{order.timeId}}小时</view>
					</view>
				</view> -->
				<view v-if="!order.timeId&&!order.areaId">
					<view v-if="order.moneyJson && order.moneyJson.distance"
						class="flex align-center justify-between margin-tb">
						<view>总公里数</view>
						<view>{{order.moneyJson.distance}}km</view>
					</view>
					<view v-if="order.moneyJson && order.moneyJson.kilometer"
						class="flex align-center justify-between margin-tb">
						<view>基础公里数</view>
						<view>{{order.moneyJson.kilometer}}km</view>
					</view>
					<view v-if="order.moneyJson && order.moneyJson.initMoney"
						class="flex align-center justify-between margin-tb">
						<view>基础起步价</view>
						<view>￥{{order.moneyJson.initMoney}}</view>
					</view>
					<view v-if="order.moneyJson && order.moneyJson.metre"
						class="flex align-center justify-between margin-tb">
						<view>超出部分公里数</view>
						<view>{{order.moneyJson.metre}}km</view>
					</view>
					<view v-if="order.moneyJson && order.moneyJson.unitOverMoney"
						class="flex align-center justify-between margin-tb">
						<view>超出部分每公里价格</view>
						<view>￥{{order.moneyJson.unitOverMoney}}</view>
					</view>
					<view v-if="order.moneyJson && order.moneyJson.otherMoney"
						class="flex align-center justify-between margin-tb">
						<view>超出部分收费总金额</view>
						<view>￥{{order.moneyJson.otherMoney}}</view>
					</view>
					<view v-if="order.moneyJson && order.moneyJson.durationAllMoney"
						class="flex align-center justify-between margin-tb">
						<view>总时长费</view>
						<view>￥{{order.moneyJson.durationAllMoney}}</view>
					</view>
				</view>
				<view class="flex align-center justify-between margin-tb" v-if="order.couponMoney">
					<view>优惠劵</view>
					<view>-￥{{order.couponMoney}}</view>
				</view>
			</view>
			<view class="margin-tb" v-if="order.remarks">
				<view>备注</view>
				<view class="margin-top-xs">{{order.remarks}}</view>
			</view>

			<view class="flex align-center justify-between margin-tb">
				<view>订单号码</view>
				<view @click.stop="copyClick(order.indentNumber)">{{order.indentNumber}}
					<image src="../static/copy.png" style="width:28rpx;height: 28rpx;"></image>
				</view>
			</view>
			<view class="flex align-center justify-between margin-tb">
				<view>下单时间</view>
				<view>{{order.createTime}}</view>
			</view>
			<view v-if="order.startWaitTime" class="flex align-center justify-between margin-tb">
				<view>开始等待时间</view>
				<view>{{order.startWaitTime?order.startWaitTime:'暂无'}}</view>
			</view>
			<view v-if="order.endWaitTime" class="flex align-center justify-between margin-tb">
				<view>结束等待时间</view>
				<view>{{order.endWaitTime?order.endWaitTime:'暂无'}}</view>
			</view>
			<view v-if="order.waitTime" class="flex align-center justify-between margin-tb">
				<view>等待总时长(分钟)</view>
				<view>{{order.waitTime?order.waitTime:'暂无'}}</view>
			</view>
			<view v-if="order.freeWaitTime" class="flex align-center justify-between margin-tb">
				<view>免费等待时长(分钟)</view>
				<view>{{order.freeWaitTime?order.freeWaitTime:'暂无'}}</view>
			</view>
			<view class="flex align-center justify-between margin-tb">
				<view>等待总费用</view>
				<view>{{order.waitMoney?order.waitMoney:0}}</view>
			</view>
			<view class="flex align-center justify-between margin-top" v-if="order.modeOfPayment">
				<view>支付方式</view>
				<view v-if="order.modeOfPayment==1">微信支付</view>
				<view v-if="order.modeOfPayment==2">支付宝支付</view>
				<view v-if="order.modeOfPayment==0">余额支付</view>
			</view>
		</view>

		<view class="tabber" v-if="order.indentState < 4">
			<view class="btn" v-if="order.indentState==1||order.indentState==2" @click.stop="qxOrder()">取消订单</view>
			<view class="btn2" v-if="order.indentState==1 && order.userId" @click.stop="openZd()">转单</view>
			<view class="btn2" v-if="order.indentState==1 && !order.startWaitTime" @click.stop="startAddress()">开始等待
			</view>

			<view class="btn2" v-if="order.indentState==2 && order.moneyType == 1" @click.stop="addTime()">加时</view>
			<view class="btn2" v-if="order.indentState==2" @click.stop="wcOrder()">抵达终点</view>
			<!-- <view class="btn1 " v-if="order.indentState==3&&order.payUser==1" @click="orderpay()">出示收款码</view> -->
			<view class="btn1 " v-if="order.indentState==3" @click="orderpay()">{{PaySwitch=='否'?'出示收款码':'线下收款'}}</view>
			<view class="btn1" @click.stop="openMapAdd()" v-if="!order.deliveryAddress&&order.indentState==1">选择终点
			</view>
			<view class="btn2" v-if="order.indentState==1&&order.deliveryAddress" @click.stop="daodaOrder()">开始服务</view>
			<!-- <view class="btn1">再来一单</view> -->
		</view>

		<u-popup v-model="show" mode="center" border-radius="14" :closeable="true" close-icon="close">
			<view class="margin-top-xs text-center" style="font-weight: bold;margin-top: 24rpx;">打开微信扫一扫</view>
			<view class="padding">
				<view>
					<uv-qrcode ref="qrcode" :value="qrcode"></uv-qrcode>
				</view>

			</view>

		</u-popup>

		<!-- 转单弹框 -->
		<u-popup v-model="shows" mode="center" border-radius="18" width="580rpx" height="400rpx">
			<view class="receipt_code">
				<view class="code_title">转单</view>
				<u-input v-model="phone" type="number" maxlength="11" placeholder="请输入转单人手机号码" :border="true"
					:clearable="false" />
				<view class="sure" @click="zhundan()">确定</view>
			</view>
		</u-popup>
		<!-- 选择时间段弹窗 -->
		<u-select v-model="showTime" @cancel="cancelTime" cancel-text="取消" label-name="timeNum" value-name="timeId"
			@confirm="confirmTime" :list="timeList"></u-select>

		<u-popup :show="isShowTipImgs" zIndex="99999999" mode="top">
			<view class="tips">
				申请麦克风权限，便于您使用该功能上传您的语音，
			</view>
		</u-popup>
	</view>
</template>

<script>
	// #ifdef H5
	var recorder; // 定义一个MediaRecorder对象
	var stream; //定义一个音频流的对象
	var chunks = []; // 定义一个用于存储音频数据片段的数组
	// #endif
	import configdata from '@/common/config.js';
	export default {
		data() {
			return {
				//录音相关参数
				// #ifndef H5
				//H5不能录音
				RECORDER: uni.getRecorderManager(),
				// #endif
				isShowTipImgs: false,
				//播放语音相关参数
				AUDIO: uni.createInnerAudioContext(),
				playMsgid: null,
				VoiceTimer: null,
				contentUrl: '',
				recordLength: '',
				voicePaths: '',
				voicePath: '',
				blobData: '',
				city: '',
				recordTimer: null,
				showTime: false,
				indentNumber: '',
				order: [],
				indentId: '',
				show: false,
				qrcode: '',
				time: '',
				creditScore: 0,
				AllcreditScore: 0,
				shows: false,
				phone: '',
				timeList: [],
				timeId: '',
				timeIdName: '',
				PaySwitch: '否',
				timerOrder: null
			}
		},
		onHide() {
			this.voiceEnd()
			this.AUDIO.stop();
			clearInterval(this.timerOrder)
		},
		onUnload() {
			clearInterval(this.timerOrder)
		},
		onLoad(option) {
			this.PaySwitch = uni.getStorageSync('PaySwitch')
			this.indentId = option.indentId
			if (option.indentNumber) {
				this.indentNumber = option.indentNumber
				this.getorderDet()
			}
			var that = this
			that.timerOrder = setInterval(() => {
				that.getorderDet()
			}, 3000)
			// #ifndef H5
			//录音开始事件
			that.RECORDER.onStart((e) => {
				console.log('监听开始录音' + e)
			})
			//录音结束事件
			that.RECORDER.onStop((e) => {
				console.log('监听结束录音' + e)
				that.recordEnd(e);
			})
			// #endif
			that.$Request.getT('/app/indent/getRiderIndentList?page=1&limit=2&indentState=2').then(
				res => {
					if (res.code === 0) {
						if (res.data.records && res.data.records.length != 0) {
							that.StartMp()
						} else {
							uni.removeStorageSync('orderIndentId')
						}
					}
				});
			that.$Request.getT('/app/common/type/364').then(res => { // 每次取消扣除的信用分数量 364
				if (res.code == 0) {
					if (res.data && res.data.value) {
						that.creditScore = res.data.value
					}
				}
			})
			that.$Request.getT('/app/common/type/365').then(res => { // 低于多少不能接单和下单 365
				if (res.code == 0) {
					if (res.data && res.data.value) {
						that.AllcreditScore = res.data.value
					}
				}
			})
		},
		onShow() {

		},
		methods: {
			openMapAdd() {
				let that = this
				uni.chooseLocation({
					success: function(res) {
						console.log('位置名称：' + res.name);
						console.log('详细地址：' + res.address);
						console.log('纬度：' + res.latitude);
						console.log('经度：' + res.longitude);
						that.selectCity(res.longitude, res.latitude)
					}
				});

			},
			selectCity(longitude, latitude) {
				this.$Request.getT('/app/Login/selectCity?lat=' + latitude + '&lng=' + longitude).then(res => {
					if (res.code === 0) {
						let that = this
						that.$Request.postJson('/app/indent/newIndentReceiving', {
							indentId: that.indentId,
							deliveryAddress: res.data.address,
							deliveryAddressLongitude: longitude,
							deliveryAddressLatitude: latitude,
							deliveryAddressId: '',
							deliveryProvince: res.data.province,
							deliveryCity: res.data.city,
							deliveryDistrict: res.data.district,
							moneyType: that.order.moneyType
						}).then(ret => {
							if (ret.code == 0) {
								that.getorderDet()
							} else {
								uni.showToast({
									title: ret.msg,
									icon: 'none'
								})
							}
						});

					}
				});
			},
			cancelTime() {
				this.timeId = ''
				this.timeIdName = ''
				this.showTime = false
			},
			confirmTime(e) {
				this.timeId = e[0].value
				this.timeIdName = e[0].label
				let that = this
				uni.showModal({
					title: '提示',
					content: '确认加时' + this.timeIdName + '吗？',
					complete(ret) {
						if (ret.confirm) {
							let data = {
								indentId: that.order.indentId,
								timeId: that.timeId
							}
							that.$Request.postT('/app/indentTimeRecord/indentAddTime', data).then(res => {
								if (res.code == 0) {
									uni.showToast({
										title: '加时成功'
									})
									that.getorderDet()
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none'
									})
								}
							})
							console.log(data, '222222222222')
						}
					}
				})
				console.log(e[0], '444444444444')
			},
			//加时
			addTime() {
				let city = this.city ? this.city : ''
				if (city === '') {
					uni.showToast({
						title: '暂无可加时长'
					})
					return;
				}
				this.$Request.get('/app/packageTime/getPackageTimeList?cityName=' + city).then(res => {
					if (res.code == 0) {
						res.data.records.map(item => {
							if (item.timeNum < 1) {
								item.timeNum = (item.timeNum * 60) + '分钟'
							} else {
								item.timeNum = item.timeNum + '小时'
							}
							// item.timeNum = item.timeNum + '小时'
						})
						this.timeList = res.data.records
						if (this.timeList.length > 0) {
							this.showTime = true
						} else {
							uni.showToast({
								title: '暂无可加时长'
							})
						}
					}
				})
			},
			zhundan() {
				if (!this.phone) {
					uni.showToast({
						title: '请输入手机号',
						icon: 'none'
					})
					return
				}
				this.$Request.postT('/app/indent/transferOfOrder', {
					indentId: this.indentId,
					phone: this.phone
				}).then(res => {
					this.shows = false
					this.phone = ''
					if (res.code == 0) {
						uni.showToast({
							title: '转单成功',
							icon: 'none',
							duration: 3000
						})
						this.getorderDet()
						setTimeout(function() {
							uni.navigateBack()
						}, 1000)
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				});
			},
			openZd() {
				this.phone = ''
				this.shows = true
			},
			orderpay() {
				let data = {
					indentId: this.indentId
				}
				if (this.PaySwitch == '否') {
					this.$Request.postT('/app/wxPay/generateNative', data).then(res => {
						if (res.code === 0 && res.data) {
							this.qrcode = res.data
							this.show = true
							let that = this
							that.time = setInterval(function() {
								that.getorderDet()
							}, 3000)
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
						}
					});
				} else {
					this.$Request.postT('/app/indent/riderPay', data).then(res => {
						if (res.code === 0) {
							this.getorderDet()
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
						}
					});
				}

			},
			copyClick(copy) {
				uni.setClipboardData({
					data: copy,
					success: function(res) {
						uni.getClipboardData({
							success: function(res) {
								uni.showToast({
									title: "复制成功",
									icon: 'none',
								});
							},
						});
					},
				});
			},
			// 一键导航
			openMap(latitude, longitude, name) {
				uni.openLocation({
					latitude: latitude - 0, //要去的纬度-地址       
					longitude: longitude - 0, //要去的经度-地址
					name: name, //地址名称
					address: name, //详细地址名称
					success: function() {
						console.log('导航成功');
					},
					fail: function(error) {
						console.log(error)
					}
				});
			},
			bindPhone(phone) {
				uni.makePhoneCall({
					phoneNumber: phone //仅为示例
				});
			},
			timing(second) {
				//实时返回计时时间
				// console.log(second)
			},
			reset() {
				//重置计时器
				this.$refs.timer.reset()
			},
			start() {
				//手动开启计时器
				this.$refs.timer.start()
			},
			clear() {
				//停止计时器
				this.$refs.timer.clear()
			},
			getDifference(date1, date2) {
				var a = new Date(date1); // 当前时间
				var b = new Date(date2); // 开始等待时间
				const diffInMs = Math.abs(b.getTime() - a.getTime());
				console.log(diffInMs, '=======')
				return diffInMs / 1000;
			},
			getorderDet() {
				let data = {
					indentNumber: this.indentNumber
				}
				this.$Request.getT('/app/indent/riderGetIndentInfo', data).then(res => {
					if (res.code === 0) {
						this.order = res.data
						if (this.order.indentState != 3) {
							clearInterval(this.time)
							this.show = false
						}
						if (this.order.moneyJson) {
							let moneyJson = JSON.parse(this.order.moneyJson)
							this.order.moneyJson = moneyJson
						}

						if (this.order.shipUserPhone) {
							let mobile = this.order.shipUserPhone
							this.order.shipPhone = mobile.substring(0, 3) + "****" + mobile.substring(7)
						}
						if (this.order.customPhone) {
							let mobile = this.order.customPhone
							this.order.customPhones = mobile.substring(0, 3) + "****" + mobile.substring(7)
						}

						const now = new Date();
						const year = now.getFullYear();
						const month = now.getMonth() + 1; // 月份是从0开始的，所以需要+1
						const day = now.getDate();
						const hours = now.getHours();
						const minutes = now.getMinutes();
						const seconds = now.getSeconds();
						let today =
							`${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')} ${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`

						if (this.order.startWaitTime && this.order.indentState == 1) {
							console.log(today, this.order.startWaitTime)
							let timestamp = this.getDifference(today, this.order.startWaitTime)
							// console.log(timestamp,'=========+++++++++' ); 
							this.order.numberminutes = timestamp
							this.order.isTime = true
						} else {
							this.order.isTime = false
						}
						if (this.order.indentState == 4 && this.order.finishTime) {
							var newTime = new Date()
							let finishTime = new Date(newTime).getTime()
							let date = new Date(this.order.finishTime)

							var y = date.getFullYear();
							var m = (date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : (date
								.getMonth() + 1);
							var d = date.getDate() < 10 ? ("0" + date.getDate()) : date.getDate();

							var f = date.getMinutes() < 10 ? ('0' + date.getMinutes()) : date
								.getMinutes() + 30
							var fen = 0
							if (f > 60) {
								var h = date.getHours() < 10 ? ('0' + date.getHours()) : date.getHours() + 1
								let  fmin = f - 60
								fen = fmin < 10 ? ('0' + fmin) : fmin
								console.log(fen, '******')
							} else {
								var h = date.getHours() < 10 ? ('0' + date.getHours()) : date.getHours()
								fen = date.getMinutes() < 10 ? ('0' + date.getMinutes()) : date
									.getMinutes() + 30
							}
							console.log(date.getSeconds(), '++++++++++++++')
							let s = date.getSeconds()
							if(s < 10){
								var smin ='0' + s
							}else{
								var smin = s
							}
							
							var formatdate = y + '-' + m + '-' + d + ' ' + h + ":" + fen + ":" + smin;
							console.log(this.order.finishTime, formatdate, '++++++++++++++')
							let nowTime = new Date(formatdate).getTime()
							console.log(finishTime, nowTime, finishTime <= nowTime, '-------------')
							if (finishTime <= nowTime) {
								this.order.isData = true
							} else {
								this.order.isData = false
							}
						} else {
							this.order.isData = true
						}
						// console.log(nowTime >= finishTime, 	this.order.isData, '-------------')

						if (this.order.shipAddressLatitude && this.order.shipAddressLongitude && this.order
							.indentState == 2 && this.order.moneyType == 1) {
							let data = {
								lat: this.order.shipAddressLatitude,
								lng: this.order.shipAddressLongitude
							}
							this.$Request.getT('/app/Login/selectCity', data).then(res => {
								if (res.code === 0) {
									this.city = res.data.city
								}
							});
						}
					}
				});
			},
			// 取消订单
			qxOrder() {
				let that = this
				let content = ''
				if (uni.getStorageSync('DepositSwitch') == '是') {
					content = '取消订单将会被扣保证金以及信用分' + that.creditScore + '分,信用分低于' + that.AllcreditScore + '分无法接单'
				} else {
					content = '取消订单将会被扣信用分' + that.creditScore + '分,信用分低于' + that.AllcreditScore + '分无法接单'
				}
				uni.showModal({
					title: '提示',
					content: content,
					cancelText: '取消',
					confirmText: '确认',
					complete: function(ret) {
						if (ret.confirm) {
							if (that.order.indentState == 2) {
								uni.removeStorageSync('orderIndentId')
								that.voiceEnd()
							}
							that.$Request.postT('/app/indent/riderCancelIndent', {
								indentId: that.order.indentId
							}).then(res => {
								if (res.code == 0) {
									uni.showToast({
										title: '订单已取消',
										icon: "none"
									});
									that.getorderDet()
									setTimeout(function() {
										uni.navigateBack()
									}, 1000)
								} else {
									uni.showToast({
										title: res.msg,
										icon: "none"
									});
								}
							});
						}
					}
				})
			},
			startAddress(indentId) {
				let that = this
				uni.showModal({
					title: '提示',
					content: '确认已抵达起点，开始等待吗？',
					complete(ret) {
						if (ret.confirm) {
							that.$Request.getT('/app/indent/riderWaitDrive?indentId=' + that.order.indentId).then(
								res => {
									if (res.code == 0) {
										uni.showToast({
											title: '已开始等待'
										})
										that.getorderDet()
									} else {
										uni.showToast({
											title: res.msg,
											icon: 'none'
										})
									}
								})
						}
					}
				})
			},
			// 获取进行中订单
			getFwzOrder() {
				this.$Request.getT('/app/indent/getRiderIndentList?page=1&limit=10&indentState=2').then(
					res => {
						if (res.code === 0) {
							if (res.data.records && res.data.records.length != 0) {
								uni.setStorageSync('orderIndentId', res.data.records[0].indentId)
								console.log(res.data.records[0].indentId, 'uni.getStorageSync')
							} else {
								clearInterval(this.timer)
								uni.removeStorageSync('orderIndentId')
							}
						}
					});
			},
			daodaOrder() { //抵达起点  开始服务
				let that = this
				that.StartMp()
				uni.showModal({
					title: '提示',
					content: '确认开始服务吗？',
					success: function(res) {
						if (res.confirm) {
							that.$Request.postT('/app/indent/riderStartDrive', {
								indentId: that.order.indentId
							}).then(res => {
								if (res.code == 0) {
									that.getorderDet()
									that.getFwzOrder()
									that.StartMp()
									uni.showToast({
										title: '服务已开始',
										icon: "none"
									});

								} else {
									uni.showToast({
										title: res.msg,
										icon: "none"
									});
								}
							});
						}
					}
				})
			},
			StartMp() { //  开始录音
				let that = this
				// #ifdef APP
				// 在弹出选择弹框之前先判断一下是否获取了相册权限
				const sysInfo = uni.getSystemInfoSync()
				if (sysInfo.osName == 'ios') { //ios

				} else { //安卓
					var Manifest = plus.android.importClass("android.Manifest");
					var MainActivity = plus.android.runtimeMainActivity();
					let flag = MainActivity.checkSelfPermission(Manifest.permission.RECORD_AUDIO)
					console.log(flag); // 查看是否拥有相机权限 -1/0
					if (flag == -1) { //没有授权
						that.isShowTipImgs = true
						plus.android.requestPermissions(['android.permission.RECORD_AUDIO'], (success) => {
							that.isShowTipImgs = false
						}, (err) => {
							that.isShowTipImgs = false
						})
						return
					} else {
						that.isShowTipImgs = false
					}

				}
				// #endif
				// #ifdef H5
				if (stream) {
					stream.getTracks().forEach((track) => track.stop())
					stream = null
				}
				if (recorder) {
					recorder = null
				}
				that.recordLength = 0
				that.voicePaths = '';
				that.voicePath = '';
				that.startRecord()
				// #endif
				// #ifndef H5
				that.RECORDER.start({
					format: "mp3"
				}); //录音开始,
				that.recordBegin()
				// #endif
			},
			//开始录音
			startRecord: async function() {
				let _this = this
				// 获取麦克风音频数据流
				stream = await navigator.mediaDevices.getUserMedia({
					audio: true
				})
				// 初始化MediaRecorder对象
				recorder = new MediaRecorder(stream);
				// 将 stream 转成 blob 来存放
				recorder.ondataavailable = (blobEvent) => {
					chunks.push(blobEvent.data);
				}
				// 停止时生成预览的 blob url
				recorder.onstop = () => {
					const blob = new Blob(chunks, {
						type: 'audio/mp3'
					})
					_this.voicePaths = blob;
					_this.blobData = blob;

				}
				recorder.start();
				_this.recordBegin()
			},
			//录音开始UI效果
			recordBegin() {
				this.recordLength = 0;
				this.recordTimer = setInterval(() => {
					this.recordLength++;
				}, 1000)
			},
			// 结束录音
			voiceEnd() {
				//原生录音停止
				// #ifdef H5
				//停止录音
				if (recorder.state != "inactive") {
					recorder.stop();
				}
				//把音频流也停止掉
				stream.getTracks().forEach((track) => track.stop())
				this.uplodMp3(this.voicePaths);
				// #endif

				// #ifndef H5
				this.RECORDER.stop(); //录音结束
				// #endif

			},
			//录音结束(回调文件)
			recordEnd(e) {
				clearInterval(this.recordTimer);
				// uni.showLoading({
				// 	title: '发送中'
				// });
				console.log(e.tempFilePath, '///////////')
				if (e.tempFilePath && this.indentId && this.recordLength > 3) {
					let that = this
					uni.uploadFile({ // 上传接口
						url: that.config("APIHOST1") + '/app/indent/uploadIndent?indentId=' + that
							.indentId, //真实的接口地址
						filePath: e.tempFilePath,
						name: 'file',
						success: (uploadFileRes) => {
							uni.hideLoading();
							let url = JSON.parse(uploadFileRes.data)
							if (url.code == 0) {
								console.log('上传成功')
								that.getorderDet()

							} else {
								uni.showToast({
									title: url.msg,
									icon: 'none'
								})
							}

						},
						fail: (err) => {
							console.log('err' + err)
						}
					});
				}
			},
			//上传mp3格式的音频
			uplodMp3(recordPath) {
				let _this = this;
				clearInterval(_this.recordTimer);
				if (_this.indentId && _this.blobData && _this.recordLength > 3) {
					uni.uploadFile({ // 上传接口
						url: _this.config("APIHOST1") + '/app/indent/uploadIndent?indentId=' + _this
							.indentId, //真实的接口地址
						file: _this.blobData,
						name: 'file',
						success: (uploadFileRes) => {
							uni.hideLoading();
							let url = JSON.parse(uploadFileRes.data)
							if (url.code == 0) {
								that.getorderDet()
							} else {
								uni.showToast({
									title: url.msg,
									icon: 'none'
								})
							}
						}
					});
				}
			},
			config: function(name) {
				var info = null;
				if (name) {
					var name2 = name.split("."); //字符分割
					if (name2.length > 1) {
						info = configdata[name2[0]][name2[1]] || null;
					} else {
						info = configdata[name] || null;
					}
					if (info == null) {
						let web_config = cache.get("web_config");
						if (web_config) {
							if (name2.length > 1) {
								info = web_config[name2[0]][name2[1]] || null;
							} else {
								info = web_config[name] || null;
							}
						}
					}
				}
				return info;
			},
			wcOrder() { //抵达终点
				let that = this
				uni.showModal({
					title: '提示',
					content: '确认已抵达终点，完成服务吗？',
					success: function(res) {
						if (res.confirm) {
							that.$Request.postT('/app/indent/riderDelivery', {
								indentId: that.order.indentId
							}).then(res => {
								if (res.code == 0) {
									that.getorderDet()
									that.voiceEnd()
									uni.showToast({
										title: '已到达终点',
										icon: "none"
									});

									// setTimeout(function() {
									// 	uni.navigateBack()
									// }, 1000)
								} else {
									uni.showToast({
										title: res.msg,
										icon: "none"
									});
								}
							});
						}
					}
				})
			},
		}
	}
</script>

<style lang="less">
	page {
		background: #F5F5F5;
	}

	.tips {
		width: 100%;
		padding: 30rpx;
		font-size: 26rpx;
		color: #333333;
		position: fixed;
		top: 50rpx;
		left: 0;
		z-index: 99999 !important;
		background-color: #ffffff;
	}

	.boxa {
		background: #FFFFFF;
		border-radius: 24rpx;
		margin: 30rpx;
		padding: 30rpx 0;
	}

	.box {
		background: #FFFFFF;
		border-radius: 24rpx;
		padding: 30rpx;
		margin: 30rpx;

	}

	.titls {
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
	}

	.bb {
		width: 110rpx;
		height: 38rpx;
		// background: #49A5FF;
		// opacity: 0.32;
		background-color: rgba(73, 165, 255, 0.3);
		border-radius: 4rpx;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #359CFF;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-left: 10rpx;
	}

	.addbox {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 30rpx;
		height: 110rpx;
		border-radius: 16rpx;

	}

	.add_cont {
		display: flex;
		align-items: center;
	}

	.add_tit {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
	}

	.bg {
		background: #F5F5F5;
	}

	.bgs {
		background: #F5F8FF;

	}

	.green {
		width: 16rpx;
		height: 16rpx;
		background: #1FC657;
		border-radius: 50%;
		margin-right: 20rpx;
	}

	.orgin {
		width: 16rpx;
		height: 16rpx;
		background: #FBAC04;
		border-radius: 50%;
		margin-right: 20rpx;
	}

	.tabber {
		background: #FFFFFF;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 9;
		display: flex;
		align-items: center;
		justify-content: end;
		padding: 10rpx 30rpx;

		.btn {
			width: 100%;
			height: 78rpx;
			border: 1px solid #A0A0A0;
			border-radius: 16rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #9C9C9C;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.btn1 {
			width: 100%;
			height: 78rpx;
			background: linear-gradient(87deg, #346EF6 0%, #7BA2FF 100%);
			border-radius: 16rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-left: 20rpx;
		}

		.btn2 {
			width: 100%;
			height: 78rpx;
			background: linear-gradient(87deg, #346EF6 0%, #7BA2FF 100%);
			border-radius: 16rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-left: 20rpx;
		}
	}

	/* 收货码弹框 */
	.receipt_code {
		width: 90%;
		margin: 0 auto;
	}

	.code_title {
		width: 100%;
		line-height: 100rpx;
		font-size: 31rpx;
		font-weight: bold;
		text-align: center;
		letter-spacing: 2rpx;
		margin-top: 21rpx;
		margin-bottom: 10rpx;
	}

	/deep/.u-input--border {
		border: 1px solid #F2F2F2 !important;
		background: #F2F2F2 !important;
		color: #999999 !important;
		font-weight: 500 !important;
		letter-spacing: 2rpx !important;
	}

	/deep/.u-input__input {
		font-size: 30rpx;
		font-weight: bold;
		flex: 1;
		color: #999999 !important;
		min-height: 85rpx !important;
		margin-top: 7rpx;
	}

	.sure {
		width: 100%;
		height: 80rpx;
		background: linear-gradient(87deg, #346EF6 0%, #7BA2FF 100%);
		color: white;
		border-radius: 46rpx;
		text-align: center;
		line-height: 80rpx;
		margin-top: 40rpx;
		letter-spacing: 2rpx;
	}
</style>